package com.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.base.comm.CommContent;
import com.base.po.sqlparam.CallbackinfoesExamplePage;
import com.base.po.voip.Callbackinfoes;
import com.base.po.voip.CallbackinfoesExample.Criteria;
import com.base.service.CallbackinfoesService;
import com.base.service.LogsService;
import com.base.utils.IP;

/**
 * admin管理系统控制器
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/admin")
public class content_home {

	@Autowired
	private CallbackinfoesService callbackinfoesService;
	@Autowired
	private LogsService logsService;// log日志
	
	// 用户首页
	@RequestMapping("/content_home")
	public ModelAndView index(HttpServletRequest request) throws Exception {
		// 返回ModelAndView
		ModelAndView modelAndView = new ModelAndView();
		CallbackinfoesExamplePage examplePage = new CallbackinfoesExamplePage();
		examplePage.pagesize = 10;
		examplePage.start = 0;
		examplePage.rows = examplePage.pagesize;// 设置首次分页
		examplePage.setOrderByClause("CallTime");
		String adminUserId = (String) request.getSession().getAttribute("adminUserId");
		Integer adminUsergrade = (Integer) request.getSession().getAttribute("adminUsergrade");
		Integer isLTH = (Integer) request.getSession().getAttribute("isLTH");
		List<Callbackinfoes> callbackinfoes = null;
		Criteria criteria = examplePage.createCriteria();
		switch (adminUsergrade) {
		case 1:
			examplePage.getOredCriteria().add(criteria.andParentidEqualTo(adminUserId));
			break;
		case 2:
			examplePage.getOredCriteria().add(criteria.andShopidEqualTo(adminUserId));
			break;
		}
		/*
		 * 设置分页
		 */
		int totlenum = callbackinfoesService.countByExample(examplePage);// 页面总数
		request.setAttribute("totlenum", totlenum);// 传入session中
		request.setAttribute("curPage", 1);// 传入session中
		callbackinfoes = callbackinfoesService.selectByExamplePage(examplePage);
		if (callbackinfoes != null) {
			// 设置页面进行跳转
			if (adminUserId.equals("0b8a2f00271e40b9aea750264bf1bb58")||isLTH==1){
				modelAndView.setViewName("jsp/content_home_lth");
				request.setAttribute("list", callbackinfoes);
			}else {
				modelAndView.setViewName("jsp/content_home");
				request.setAttribute("list", callbackinfoes);
			}
			return modelAndView;
		}

		String usernamesys = (String) request.getSession().getAttribute("useracc");
		logsService.insert(CommContent.TYPE_SYS, CommContent.LOGS_READ + "首页信息", usernamesys, true,
				IP.getIpAddr(request));
		modelAndView.setViewName("jsp/datanotfound");
		return modelAndView;
	}
}
